﻿using DFGJ.WMS_PDA.WebAPI.Extensions;
using DFGK_WMS.IRepository;
using DFGK_WMS.Model.Models;
using DFGK_WMS.WebAPI.Controllers.Result;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace DFGJ.WMS_PDA.WebAPI.Controllers.PDA
{
    [ApiController]
    [Route("api/[controller]/[action]")]
    [ApiExplorerSettings(IgnoreApi = false, GroupName = nameof(ApiVersions.V1))]
    [AllowAnonymous]

    public class TransferBinOrdersController : ApiBaseController
    {
        public TransferBinOrdersController(ITTransferBinOrderRepository tTransferBinOrderRepository)
        {
            TTransferBinOrderRepository = tTransferBinOrderRepository;
        }

        public ITTransferBinOrderRepository TTransferBinOrderRepository { get; }

        /// <summary>
        /// 提交（有网）
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>'

        [HttpPost]
        public IActionResult UpTransferBinOrderStatus(TTransferBinOrderDetail m)
        {
            if (m.Id <= 0)
            {
                return Ok(BaseResult.Result("400", "Id有误！"));
            }
            string message;
            bool IsOK = TTransferBinOrderRepository.UpTransferBinOrderStatus(m, out message);
            if (IsOK)
            {
                return Ok(BaseResult.Result(true, "修改成功！", "200"));
            }

            return Ok(BaseResult.Result(false, message, "500"));
        }


        /// <summary>
        /// 获取单号状态为2的单号
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetTransferBinOrderSn()
        {
            var list = TTransferBinOrderRepository.GetTransferBinOrderSn();
            if (list.Count >= 0)
            {
                return Ok(BaseResult.Result(list, "查询成功！", "200"));
            }
            return Ok(BaseResult.Result(null, "查询失败", "500"));
        }


        /// <summary>
        /// 根据单号获取详情
        /// </summary>
        /// <param name="orderSn"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetTransferBinOrderDetailsByOrderSn(string orderSn)
        {
            var list = TTransferBinOrderRepository.GetTransferBinOrderDetailsByOrderSn(orderSn);
            if (list.Count >= 0)
            {
                return Ok(BaseResult.Result(list, "查询成功！", "200"));
            }
            return Ok(BaseResult.Result(null, "查询失败", "500"));
        }
    }
}
